#!/bin/bash

# 确保脚本目录存在
mkdir -p scripts

# 检查 MySQL 客户端是否安装
if ! command -v mysql &> /dev/null; then
    echo "MySQL client not found. Please install MySQL client."
    exit 1
fi

# 提示用户输入 MySQL root 密码
echo "Please enter MySQL root password:"
read -s MYSQL_ROOT_PASSWORD

# 执行 SQL 脚本
mysql -u root -p"$MYSQL_ROOT_PASSWORD" < scripts/init-mysql.sql

# 检查执行结果
if [ $? -eq 0 ]; then
    echo "MySQL user 'dynamic_user' and database 'dynamic_db' created successfully."
else
    echo "Failed to create MySQL user and database."
    exit 1
fi

# 更新 .env 文件
cat > .env << EOF
# 数据库类型: postgres 或 mysql
DB_TYPE=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_USER=dynamic_user
DB_PASSWORD=dynamic_password
DB_NAME=dynamic_db
EOF

echo ".env file updated with MySQL configuration." 